Skip to content

Fix #886: use default instead of null for optional struct ByRef parameters#1253

Open
GrahamTheCoder wants to merge 2 commits intoicsharpcode:masterfrom
GrahamTheCoder:claude/fix-issue-886-optional-struct-ref
Open

Fix #886: use default instead of null for optional struct ByRef parameters#1253
GrahamTheCoder wants to merge 2 commits intoicsharpcode:masterfrom
GrahamTheCoder:claude/fix-issue-886-optional-struct-ref

Conversation

@GrahamTheCoder
Copy link
Copy Markdown
Member

Fixes #886

When a VB optional ByRef parameter has a struct type with Nothing as default, Roslyn returns null from ExplicitDefaultValue. Generating a null literal causes a C# compile error since structs cannot be null. Use default instead when the parameter type is a value type and the default value is null.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX

…al ByRef struct params

When a VB method has an optional ByRef struct (value type) parameter with
Nothing as the default, the converter previously generated `null` as the
initializer for the hoisted local variable. `null` is not valid for value
types in C#, causing a compilation error.

The fix introduces a `LiteralOrDefault` helper that returns the `default`
literal when the parameter type is a value type and the explicit default
value is null.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
@GrahamTheCoder GrahamTheCoder force-pushed the claude/fix-issue-886-optional-struct-ref branch from ff3cc72 to c118125 Compare April 16, 2026 08:11
…n Vsix not built

The Vsix project uses UseWPF=true with net472, which fails SDK validation
when MSBuild tries to build it as a dependency of Tests.csproj on newer
.NET SDK versions. Setting Build="false" prevents this. Also makes the
VsixDoesNotReferenceNewerBclPolyfillsThanOldestSupportedVs test skip
gracefully when the Vsix output directory is absent (matching the second test).

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VB -> C#: wrong conversion of optional struct or decimal ref parameter

2 participants